home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / uupc.lzh / uupc / getcwd.c < prev    next >
C/C++ Source or Header  |  1990-01-16  |  2KB  |  95 lines

  1. /*
  2.  *    getcwd
  3.  *
  4.  *    Amiga (Manx) Library
  5.  *
  6.  *    $Id: getcwd.c,v 1.2 90/01/16 10:25:37 crash Exp Locker: crash $
  7.  */
  8.  
  9. #ifndef lint
  10. static char RCSid[] = "$Id: getcwd.c,v 1.2 90/01/16 10:25:37 crash Exp Locker: crash $";
  11. #endif /* lint */
  12.  
  13. #include <libraries/dos.h>
  14. #include <exec/memory.h>
  15.  
  16. #ifdef MCH_AMIGA
  17. # include <functions.h>        /* Manx */
  18. #else
  19. # include <proto/exec.h>    /* Lattice */
  20. #endif
  21.  
  22. #ifdef TEST
  23. # include <stdio.h>
  24. #endif
  25.  
  26. #ifndef NULL
  27. # define NULL 0L
  28. #endif
  29.  
  30. char *malloc();
  31.  
  32. /*--------------------------------------------------------------*/
  33. /*    GetCurrentPath: get full path of the current directory    */
  34. /*--------------------------------------------------------------*/
  35.  
  36. static void GetCurrentPath( path )
  37. register char *path;
  38. {
  39.     static char s1[ 512 ];
  40.     static struct FileInfoBlock fib;
  41.  
  42.     char *name;
  43.     register struct FileLock *locka, *lockb;
  44.  
  45.     locka = Lock("", ACCESS_READ );
  46.     *path = s1[0] = '\0';
  47.     while ( locka != NULL ) {
  48.         Examine( locka, &fib );
  49.         name = fib.fib_FileName;
  50.         if ( *name == '\0' )
  51.             strcpy( path, "RAM" );        /* Patch for Ram disk bug */
  52.         else
  53.             strcpy( path, name );
  54.         lockb = ParentDir( locka );
  55.         UnLock( locka );
  56.         
  57.         if ( lockb == NULL )
  58.             strcat( path, ":");
  59.         else
  60.             if ( s1[0] != '\0' )
  61.                 strcat( path, "/");
  62.         strcat( path, s1 );
  63.         strcpy( s1, path );
  64.         locka = lockb;
  65.     }
  66. }
  67.  
  68. /*--------------------------------------------------------------*/
  69. /*    getcwd: return the path name of the current directory        */
  70. /*--------------------------------------------------------------*/
  71.  
  72. char *getcwd( path, size )
  73. char *path;
  74. int size;
  75. {
  76.     if (!path) {
  77.         if ( !(path = malloc(512)) ) {
  78. #ifdef TEST
  79.             fprintf(stderr,
  80.                 "getcwd:  malloc failed to get %d bytes\n", BUFSIZ);
  81. #endif
  82.             return NULL;
  83.         }
  84.     }
  85.     GetCurrentPath( path );
  86.     return path;
  87. }
  88.  
  89. #ifdef TEST
  90. main()
  91. {
  92.     fprintf( stderr, "%s\n", getcwd( NULL, 0 ));
  93. }
  94. #endif
  95.